from fastapi.responses import JSONResponse
from fastapi import Request
import logging

from ..main import app
from ..dto.Result import Result


@app.exception_handler(Exception)
async def globalExceptionHandler(request: Request, exc):
    logging.error(f"全局异常处理器捕获到异常: {type(exc).__name__}")
    return JSONResponse(
        status_code=200,
        content=Result.error("服务器内部错误, 请联系管理员").model_dump(),
    )
